﻿@using SCMS.Resource
@model SCMS.UI.Models.AdvanceRequestModel

<div class="partialViewCard">
    <div class="partialViewCardHeader">
        <h3>@Model.RefNumber</h3>
    </div>
    @if (Model.CanEdit)
    {
        <center>
            @Ajax.ActionLink(Resources_frank.RequestForAdvance_ViewRFADetails_EditRFA, "EditRFA", new { id = "" }, new AjaxOptions
       {
           UpdateTargetId = "R4ADiv",
           LoadingElementId = "loading",
           Url = Url.Action("EditRFA/" + Model.Id)
       }) |
            @Ajax.ActionLink(Resources_frank.RequestForAdvance_ViewRFADetails_DeleteRFA, "DeleteRFA", new { id = "" }, new AjaxOptions
       {
           UpdateTargetId = "R4ADiv",
           LoadingElementId = "loading",
           Url = Url.Action("DeleteRFA/" + Model.Id),
           Confirm = string.Format(Resources.Global_String_ConfirmDelete, Model.RefNumber),
           OnSuccess = "usermsg('" + Resources_frank.RequestForAdvance_ViewRFADetails_DeleteSuccessMsg + "');if (document.getElementById('table') != null) {initSorter();sorter.size(20);}"
       })
        </center>
    }
    else if (Model.CanApprove)
    {
        string linkText = null;
        string actionName = null;
        if (Model.IsReviewed && !Model.IsAuthorized && !Model.IsRejected)
        {
            linkText = Resources.Request4Advance_ViewRADetails_AuthorizeRFA;
            actionName = "LoadRFAForAuth";
        }
        else if (Model.IsSubmitted && !Model.IsReviewed && !Model.IsRejected)
        {
            linkText = Resources.Request4Advance_ViewRADetails_ReviewRFA;
            actionName = "ReviewRFA";
        }
        if (linkText != null)
        {
            <center id="canApprove">
                @Ajax.ActionLink(linkText, actionName, "RequestReview", new { id = "" }, new AjaxOptions
           {
               OnBegin = "ShowDialogueOR('" + linkText + ": " + Model.RefNumber + "')",
               UpdateTargetId = "popup-page",
               LoadingElementId = "popup-loading",
               Url = Url.Action(actionName + "/" + Model.Id, "RequestReview"),
               OnSuccess = "CenterPopupRFP();document.getElementById('canApprove').innerHTML ='&nbsp;';"
           }) 
            </center>
        }
    }
    else
    {
        <br />
    }
    <table width="98%" align="center" cellpadding="2" class="cardTable">
        <tr class="gridheader">
            <td colspan="3">
                @Resources.Global_String_SubjectPurpose
            </td>
        </tr>
        <tr>
            <td colspan="3">
                <b>@Model.Subject</b>
                @Html.HiddenFor(x => x.Subject)
            </td>
        </tr>
        <tr class="gridheader">
            <td>
                @Resources.Request4Advance_CreateRFA_PaymentTo
            </td>
            <td>
                @Resources.Global_String_PaymentTerms
            </td>
            <td>
                @Resources.Global_String_PaymentType
            </td>
        </tr>
        <tr>
            <td align="center">
                @Model.Payee
                @Html.HiddenFor(x => x.PaidTo)
            </td>
            <td align="center">
                @Model.PaymentTerm
                @Html.HiddenFor(x => x.PaymentTermId)
            </td>
            <td align="center">
                @Model.PaymentType
                @Html.HiddenFor(x => x.PaymentTypeId)
            </td>
        </tr>
        <tr class="gridheader">
            <td width="33%">
                @Resources.Global_String_Date
            </td>
            <td width="33%">
                @Resources.Global_String_Currency
            </td>
            <td width="34%">
                @Resources.Global_String_TotalPayment
            </td>
        </tr>
        <tr>
            <td align="center">
                @Model.RequestDate.ToString("dd/MM/yyyy")
                @Html.HiddenFor(m => m.RequestDate)
                @Html.HiddenFor(m => m.Id)
            </td>
            <td align="center">
                @Model.Currency
                @Html.HiddenFor(x => x.CurrencyId, new { @id = "currencyId" })
            </td>
            <td align="center">
                <b>@Model.TotalAdvance.ToString("#,##0.00")</b>
                @Html.HiddenFor(m => m.TotalAdvance)
            </td>
        </tr>
    </table>
    <br />
    <table class="cardTable" cellpadding="2">
        <tr class="gridheader">
            <th colspan="5" align="center">
                @Resources.Global_String_PaymentDetails
            </th>
        </tr>
        @if (Model.PaymentDetails.Count > 0)
        { 
            <tr class="gridheader">
                <th align="center">
                    @Resources.Request4Advance_CreateRFADetail_RequestFor
                </th>
                <th align="center">
                    @Resources.Global_String_Description
                </th>
                <th align="center">
                    @Resources.Budget_CategoryList_ProjectNo
                </th>
                <th align="center">
                    @Resources.Budget_CreateSubLine_LineNumber
                </th>
                <th align="center">
                    @Resources.Global_String_Amount
                </th>
            </tr>
            foreach (var detail in Model.PaymentDetails)
            { 
            <tr>
                <td>@detail.AdvanceOption
                </td>
                <td>@detail.Description
                </td>
                <td>@detail.ProjectNo
                </td>
                <td>@detail.BudgetLine
                </td>
                <td align="right">@detail.Amount.ToString("#,##0.00")
                </td>
            </tr>
            }
            <tr>
                <td align="right" colspan="5">
                    <b>@Model.TotalAdvance.ToString("#,##0.00")</b>
                </td>
            </tr>
            <tr>
                <td colspan="2" align="right" class="gridheader2">
                    @Resources.Global_String_MasterBudgetCurrency
                </td>
                <td align="center">
                    @if (!Model.MBCurrency.Equals(Guid.Empty))
                    { 
                        @Model.MBCurrencyShortName
                    }
                </td>
                <td align="right" class="gridheader2">@Resources.Global_String_Total</td>
                <td align="right">
                    <b>
                        @if (!Model.MBCurrency.Equals(Guid.Empty))
                        { 
                            @Model.MBValue.ToString("#,##0.00")
                        }
                    </b>
                </td>
            </tr>
            <tr>
                <td colspan="2" align="right" class="gridheader2">
                    @Resources.Request4Advance_ViewRADetails_VoucherNo
                </td>
                <td align="center">@Model.VoucherNo</td>
                <td align="right" class="gridheader2">@Resources.Request4Advance_ViewRADetails_AccountNo</td>
                <td align="right">@Model.AccountNo</td>
            </tr>
        }
    </table>
    @if (Model.CanPostFunds)
    { 
        <table width="98%" align="center" cellpadding="0" cellspacing="0">
            <tr>
                <td align="right" width="100%" style="padding: 3px 0px 0px 0px">
                    <input type="button" id="btnPost" name="btnPost" value="@Resources.Global_String_PostFunds" class="btn tertiary" onclick="ShowDialogue('@Resources.Global_String_AuthenticateFundsPoster'); sendRequest('/FundPosting/PostRFA/@Model.Id', 'popup-page', 'popup-loading'); CenterPopup();" />
                </td>
            </tr>
        </table>
    }
    else
    {    
        <br /> 
    }
    <table width="98%" align="center" border="0" cellpadding="2" cellspacing="2" class="cardTable">
        <tr class="gridheader">
            <td width="100%" colspan="2">
                @Resources.Request4Advance_LoadRFADetails2_DetailedDescription
            </td>
        </tr>
        <tr>
            <td colspan="2">
                @Model.Description &nbsp;
            </td>
        </tr>
        <tr class="gridheader">
            <td width="100%" colspan="2">
                @Resources.Request4Advance_LoadRFADetails2_SupportingDocuments
            </td>
        </tr>
        <tr>
            <td colspan="2">
                @Model.DocDescription &nbsp;
            </td>
        </tr>
        <tr class="gridheader">
            <td colspan="2">
                @Resources.Global_String_Remarks
            </td>
        </tr>
        <tr>
            <td colspan="2">
                @Model.Remarks &nbsp;
            </td>
        </tr>
    </table>
    <br />
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" style="border: 1px solid grey;
        border-collapse: collapse; padding: 5px; font-size: 12px;">
        <tr class="gridheader">
            <td width="19%">
                @Resources.Approver_ApproverList_Authorization
            </td>
            <td width="27%">
                @Resources.Global_String_PreparedBy
            </td>
            <td width="27%">
                @Resources.ExpenseClaim_ViewExpsClaimsDetails_FinanceReview
            </td>
            <td width="27%">
                @Resources.Global_String_AuthorizedByManager
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.Global_String_Name:
            </td>
            <td>
                @if (Model.Preparer != null)
                { 
                    @Model.Preparer.Person.FirstName 
                    @Html.Raw("&nbsp;")
                    @Model.Preparer.Person.OtherNames
                }
            </td>
            <td>
                @if (Model.Approver != null)
                { 
                    @Model.Approver.Person.FirstName 
                    @Html.Raw("&nbsp;")
                    @Model.Approver.Person.OtherNames
                }
            </td>
            <td>
                @if (Model.Authorizer != null)
                { 
                    @Model.Authorizer.Person.FirstName 
                    @Html.Raw("&nbsp;")
                    @Model.Authorizer.Person.OtherNames
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.Global_String_Title:
            </td>
            <td>
                @if (Model.Preparer != null)
                { 
                    @Model.Preparer.Designation.Name
                }
            </td>
            <td>
                @if (Model.Approver != null)
                { 
                    @Model.Approver.Designation.Name
                }
            </td>
            <td>
                @if (Model.Authorizer != null)
                { 
                    @Model.Authorizer.Designation.Name
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.Global_String_Date:
            </td>
            <td>
                @Model.PreparedOn.ToString("dd/MM/yyyy h:mm tt")
            </td>
            <td>
                @if (Model.Approver != null)
                { 
                    @Model.ApprovedOn.ToString("dd/MM/yyyy h:mm tt")
                }
            </td>
            <td>
                @if (Model.Authorizer != null)
                { 
                    @Model.AuthorizedOn.ToString("dd/MM/yyyy h:mm tt")
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.Global_String_Signature:
            </td>
            <td>
                @if (Model.Preparer != null && Model.Preparer.Person.SignatureImage != null)
                { 
                    <img src="@Url.Action("Photo", "Person", new { id = Model.Preparer.Person.Id, area = "" })" alt="" style="max-width: 100px;" />
                }
            </td>
            <td>
                @if (Model.Approver != null && Model.Approver.Person.SignatureImage != null)
                { 
                    <img src="@Url.Action("Photo", "Person", new { id = Model.Approver.Person.Id, area = "" })" alt="" style="max-width: 100px;" />
                }
            </td>
            <td>
                @if (Model.Authorizer != null && Model.Authorizer.Person.SignatureImage != null)
                { 
                    <img src="@Url.Action("Photo", "Person", new { id = Model.Authorizer.Person.Id, area = "" })" alt="" style="max-width: 100px;" />
                }
            </td>
        </tr>
    </table>
    <hr />
    @if (Model.IsAuthorized)
    {
        <a class="btn btn-primary"  href="@Url.Action("pdf", "R4A", new { area = "Reports", R4Aid = Model.Id })" target="_blank" style="margin-left: 48%; margin-bottom: 2%;">
            @Resources.Budget_ViewBudget_DownloadPdf</a>
    }
    <p>
        &nbsp; &nbsp;
        @Ajax.ActionLink(Resources.Global_String_BackToList, "ViewR4A", new { id = "ViewR4A" }, new AjaxOptions
        {
            UpdateTargetId = "R4ADiv",
            LoadingElementId = "loading",
            Url = Url.Action("ViewR4A"),
            OnSuccess = "if (document.getElementById('table') != null) {initSorter(); sorter.size(50);}"
        })
    </p>
</div>
